#include <QStyle>
#include <QStyleOption>
#include <QPainter>
#include "titleribbonbar.h"
#include "frameless/framelesswidget.h"

TitleRibbonBar::TitleRibbonBar(TitleBarElementTypes types, QWidget *parent) : QWidget(parent)
{
    layout = new QVBoxLayout;
    layout->setContentsMargins(0,0,0,0);
    layout->setSpacing(0);

    titleBar = new MainWindowTitleBar(types, this);
    // 向父窗口传递换皮肤slot
    connect(titleBar, SIGNAL(changeSkin(QString)), parent,
            SLOT(dealSkinChange(QString)));
    layout->addWidget(titleBar);

    ribbonBar = new RibbonBar;
    layout->addWidget(ribbonBar);
    setLayout(layout);

}
TitleRibbonBar::~TitleRibbonBar()
{
}

// 设置标题栏元素
void TitleRibbonBar::setTitleBarElement(TitleBarElementType type,
                        const QString content)
{
    if(titleBar)
        titleBar->setElement(type, content);
}

// 添加Ribbon工具栏类别
void TitleRibbonBar::addRibbonToolBar(RibbonToolBar *toolbar)
{
    if(ribbonBar && toolbar)
        ribbonBar->addRibbonToolBar(toolbar);
}

// 添加Ribbon工具栏下工具分组
void TitleRibbonBar::addRibbonToolButtonGroup(RibbonToolBar *toolbar,
                              RibbonToolButtonGroup *group)
{
    if(ribbonBar && toolbar && group)
        toolbar->addRibbonGroup(group);
}

// 添加Ribbon工具栏--工具分组下按钮
void TitleRibbonBar::addRibbonToolButton(RibbonToolBar *toolbar,
                         RibbonToolButtonGroup *group,
                         RibbonToolButton *ribbonToolButton)
{
    if(ribbonBar && toolbar && group && ribbonToolButton)
        group->addToolBtn(ribbonToolButton);
}


void TitleRibbonBar::paintEvent(QPaintEvent* e)
{
    Q_UNUSED(e)
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

void TitleRibbonBar::dealSkinChange(QString skinFile)
{
    emit changeSkin(skinFile);
}
